<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>更新OA知识点</title>
<base href="<%=basePath%>" />
<%@ include file="../../cuv_include.jsp"%>
<style type="text/css">
fieldset,legend,form,table,tr,td,textarea {
	margin: 0;
	padding: 0
}

form label {
	font-weight: bold;
}

table {
	margin: 10px 10px
}

;
td {
	line-height: 40px;
}

input[type="text"] {
	width: 300px;
}

input[type="password"] {
	width: 250px;
}

input[type="textarea"] {
	width: 250px;
}
</style>
<script language="JavaScript" type="text/javascript"
	src="<%=basePath%>js/my97/WdatePicker.js" defer="defer"></script>
<script type="text/javascript">
  $(document).ready(function(){
      var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
      $("#itemForm").submit(function(){
    	  $("#btn_insert").attr("disabled","disabled");
          $(this).ajaxSubmit(options);
          return false;
      }); 

    //回复信息----------------------------------------------------------------------
		 $('#commentForm').submit(function(){
			  if(isEmpty($("#comment").val()))
			  { 
			       alert("回复内容不能为空！"); 
			       return false;
			  }
           $.ajax({
               url: "<%=basePath%>req/oarepository/comment.do",   // 提交的页面
               data: $('#commentForm').serialize(),    // 从表单中获取数据
               type: "POST",                           // 设置请求类型为"POST"，默认为"GET"
               dataType: 'json',
               error: function(XMLHttpRequest, textStatus, errorThrown) {
                     alert(XMLHttpRequest.status);
               },
               success: function(data) {
               	if(data.code == 1) {
							 $("#allComment").prepend(
					    			   "<table style=' width: 83%'>"
					    			 +"   <tr>"
					    			 +"      <td ><label>"+ data.createTime+"</label>"
					    			 +"      &nbsp;&nbsp;&nbsp; <font color='red'>"+$("#usercnname").val()+"</font></td>"
					    			 +"   </tr>"
					    			 +"   <tr>"
					    			 +"      <td class='word' >	<span style='color:#00A;'>"+$("#comment").val()+"</span></td>"
					    			 +"   </tr>"
					    			 +" </table>"
					    	  );
							 $('#comment').val('');
                   }}
               });
           return false;
       });
	     //回复信息结束----------------------------------------------------------------------     
  });
  
  function beforeSubmit() {
	  if(isEmpty($("#title").val())) { $('#error_label').text("错误信息：标题不能为空！"); 
	  	$("#p_error").show();
	  	$("#btn_insert").removeAttr("disabled");
    	return false; }
	  if(isEmpty($("#content").val())) { $('#error_label').text("错误信息：内容不能为空！"); 
	  	$("#p_error").show();
	  	$("#btn_insert").removeAttr("disabled");
  		return false; }

      return true;
  }

    function process(responseJson) {
    	$("#btn_insert").removeAttr("disabled");
      if(responseJson.code == 0) {
          $('#error_label').text("错误信息：" + responseJson.message);
          $("#p_error").show();
          return;
      }
      var qs = $("#qs").val();
      location.href = "<%=basePath%>req/oarepository/list.do?" + qs;
    }  
</script>
</head>
<body>
<div style="float: left;">
	<div>
		<fieldset>
			<legend>修改OA知识：</legend>
			<form id="itemForm" method="post" action="req/oarepository/update.do">
				<input id="qs" name="qs" type="hidden" value="${qs}" />
				<p id="p_error" style="margin: 10px 10px;">
					<label id="error_label" style="color: red;"></label>
				</p>
				<table>
					<tr>
						<td><label for="title">标题：</label></td>
						<td><input type="text" name="title" id="title"
							value="${item.title }" /> <font color="red">&nbsp;*&nbsp;&nbsp;</font>
							<label for="title">0～50字</label></td>
						<td><input type="hidden" name="id" id="id"
							value="${item.id }" /></td>
						<td><input type="hidden" name="creator" id="creator"
							value="${item.creator }" /></td>
						<td><input type="hidden" name="createTime" id="createTime"
							value="${item.createTime }" /></td>
					</tr>
					<tr>
						<td valign="top"><label for="content">内容：</label></td>
						<td valign="top"><textarea name="content" id="content"
								cols="50" rows="10"><c:out value="${item.content }" /></textarea> <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
					</tr>
					<tr>
						<td valign="top"><label for="result">问题描述：</label></td>
						<td valign="top"><textarea name="problem" id="problem"
								cols="50" rows="10"><c:out value="${item.problem }" /></textarea> <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
					</tr>
					<tr>
						<td valign="top"><label for="result">备注信息：</label></td>
						<td valign="top"><textarea name="remark" id="remark"
								cols="50" rows="10"><c:out value="${item.remark }" /></textarea>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" id="btn_insert" value="提交"
							style="width: 80px;" /> <input type="button" id="btn_back"
							value="返回" onclick="history.back();" style="width: 80px;" /></td>
					</tr>
				</table>
			</form>
		</fieldset>
	</div>
	<div id="uploadDiv" style="width: 98%">
		<fieldset>
			<legend>附件信息：</legend>
			<table style="table-layout: fixed">
				<c:forEach items="${attList}" var="att" varStatus="status">
					<tr>
						<c:if test="${status.count == 1}">
							<td><label>相关文件：</label></td>
						</c:if>
						<c:if test="${status.count!=1}">
							<td></td>
						</c:if>
						<td colspan="3"><a
							href="<%=basePath%>req/oarepository/download.do?fileName=${att.name}&path=${att.path}">${att.name}</a>
						</td>
					</tr>
				</c:forEach>
			</table>
		</fieldset>
	</div>
</div>
<div class="divcomment">
		<fieldset >
			<legend>交流板</legend>
		    <form id="commentForm" >
				<table style="width: 85%">
					<tr>
						<td ><textarea name="comment" id="comment" cols="40" rows="5"></textarea>
						<input type="submit" id="send" name="send" value="发表" />
						</td>
					    <td valign="bottom">
					      <input type="hidden" name="objectId" id="objectId" value="${item.id}">
					      <input type="hidden"  id="usercnname" value="${sessionScope.usercnname}">
					    </td>
					</tr>
				</table>
		    </form>
			<div id="allComment">
			   <c:forEach  items="${comList}" var="com">
					<table>
						<tr>
							<td>
								<label for="project">
								  <fmt:formatDate value="${com.createTime}" type="both"	dateStyle="medium" timeStyle="medium" />
								</label>
								&nbsp;&nbsp;&nbsp;
								<font color="red">${com.userCnname}</font>
							</td>
						
						</tr>
						<tr>
							<td class="word">
								<span style="color:#00A;">${com.content}</span>
							</td>
						</tr>
					</table>
				</c:forEach>
			</div>
		</fieldset>
	</div>
</body>
</html>